﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace TA.DotNetUtils
{
	public class ErrorLogger
	{
		public static string LogName { get; set; }
		public static string Source { get; set; }
		static void EnsureSource(string logName, string source)
		{
			if (!EventLog.SourceExists(source))
				EventLog.CreateEventSource(source, logName);
		}
		public static void Log(Exception ex)
		{
			Log(LogName, Source, ex);
		}
		public static void Log(EventLogEntryType type, string message)
		{
			Log(LogName, Source, type, message);
		}
		public static void Log(string logName, string source, EventLogEntryType type, string message)
		{
			EnsureSource(logName, source);
			EventLog.WriteEntry(source, message, type);
		}
		public static void Log(string logName, string source, Exception ex)
		{
			Log(logName, source, EventLogEntryType.Error,  ex.ToString());
		}
	}
}
